package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.FileService;
import com.atguigu.spzx.model.vo.common.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Tag(name = "文件管理模块")
@RequestMapping("/admin/system/file")
public class FileController {
    @Resource
    FileService fileService;
    @Operation(summary = "文件上传接口")
    @PostMapping("upload")
    //module:表示本次上传的文件保存到minio桶内的哪个目录下
    public R upload(MultipartFile file,String module){//前端上传的组件表单项name值必须为file
        String path = fileService.upload(file,module);
        //返回上传成功的文件的访问地址
        return R.ok("path" , path);
    }
    @Operation(summary = "文件删除接口")
    @DeleteMapping("delete")
    public R deleteFile(String path){//根据地址删除文件
        fileService.deleteFile(path);
        return R.ok();
    }
}
